import matplotlib.pyplot as plt
import numpy as np

plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False
#直方图记录数据频次
data1 = np.random.normal(0, 1, 1000)
data2 = np.random.normal(3, 1.5, 1000)

plt.figure(figsize=(10, 6))
plt.hist(data1, bins=30, alpha=0.5, label="数据集1")
plt.hist(data2, bins=30, alpha=0.5, label="数据集2")

plt.title('直方图示例')
plt.xlabel('值')
plt.ylabel('频数')
plt.grid(True)
plt.legend()
plt.show()